package com.shaoshaohuo.app.ui.fragment;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationClient;
import com.amap.api.location.AMapLocationClientOption;
import com.amap.api.location.AMapLocationListener;
import com.bigkoo.pickerview.OptionsPickerView;
import com.google.gson.Gson;
import com.shaoshaohuo.app.R;
import com.shaoshaohuo.app.adapter.HomeTabLayoutAdapter;
import com.shaoshaohuo.app.framework.SharedPreferencesHelper;
import com.shaoshaohuo.app.net.HttpConfig;
import com.shaoshaohuo.app.ui.Search_Activity;

import org.json.JSONArray;

import java.util.ArrayList;
import java.util.List;

/**
 * @author linmu
 * @ClassName EcMainActivity
 * @Decription 电商首页
 * @2015-8-28 下午9:40:41
 */
public class EcMainFragment extends Fragment {
    ImageView imageView_search;
    private View mContentView;
    private TabLayout home_tabLayout;
    private ViewPager home_viewPager;
    private HomeTabLayoutAdapter home_tabAdapter;
    private List<String> home_tabData;
    private List<Fragment> home_tabFragment;
    private HomeTabFragment tabFragment;
    private String mArgument;
    private List<String> url_data;
    public static final String ARGUMENT = "argument";
    private HomeDomesticFragment homeDomesticFragment;
    private HomeImportationFragment homeImportationFragment;
    private HomeHotFragment homeHotFragment;
    private HomePickFragment homeBargainFragment;
    private Bundle Hotbundle;
    private Bundle DomesticBundle;
    private Bundle BargainBundle;
    private Bundle ImportationBundle;
    /*
    ===============================省市==================

     */
    private ArrayList<JsonBean> options1Items = new ArrayList<>();
    private ArrayList<ArrayList<String>> options2Items = new ArrayList<>();
    private ArrayList<ArrayList<ArrayList<String>>> options3Items = new ArrayList<>();
    private Thread thread;
    private static final int MSG_LOAD_DATA = 0x0001;
    private static final int MSG_LOAD_SUCCESS = 0x0002;
    private static final int MSG_LOAD_FAILED = 0x0003;
    private boolean isLoaded = false;
    private Handler mHandler = new Handler() {
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case MSG_LOAD_DATA:
                    break;

                case MSG_LOAD_SUCCESS:
//                    Toast.makeText(getContext(), "解析数据成功", Toast.LENGTH_SHORT).show();
                    isLoaded = true;
                    break;

                case MSG_LOAD_FAILED:
//                    Toast.makeText(getContext(), "解析数据失败", Toast.LENGTH_SHORT).show();
                    break;

            }
        }
    };
    //======================定位相关==============================
    //声明定位回调监听器
    private String startlatitude;
    private String startlongitude;
    private double latitude;
    private double longitude;
    public AMapLocationClient mLocationClient = null;
    public AMapLocationClientOption mLocationOption = null;
    public AMapLocationListener mLocationListener = new AMapLocationListener() {


        @Override
        public void onLocationChanged(AMapLocation aMapLocation) {
            if (aMapLocation.getErrorCode() == 0) {

                //纬度
                latitude = aMapLocation.getLatitude();
                //经度
                longitude = aMapLocation.getLongitude();

//                Toast.makeText(getContext(), "定位成功", Toast.LENGTH_LONG).show();
                Log.e("TAG", "onLocationChanged: 成功定位感人= = =");
                if (EcMainFragment.this.longitude > 0 && EcMainFragment.this.latitude > 0) {
                    String city = aMapLocation.getCity();
                    textView_tobar_left.setText(city);
                    SharedPreferencesHelper.setString(SharedPreferencesHelper.Field.CITY_Name, city);
                    SharedPreferencesHelper.setString(SharedPreferencesHelper.Field.CIty_latitude, latitude + "");
                    SharedPreferencesHelper.setString(SharedPreferencesHelper.Field.CIty_longitude, longitude + "");

                    sendaddress();
                }
            } else {

            }
            mLocationClient.stopLocation();//停止定位后，本地定位服务并不会被销毁
//            mLocationClient.onDestroy();//销毁定位客户端，同时销毁本地定位服务。
        }
    };
    private TextView textView_tobar_left;

    public static EcMainFragment sharedInstance(String argument) {
        Bundle bundle = new Bundle();

        bundle.putString(ARGUMENT, argument);
        EcMainFragment contentFragment = new EcMainFragment();
        contentFragment.setArguments(bundle);
        return contentFragment;
    }
  public void sendaddress(){
      Intent intent = new Intent();
      intent.setAction("address");
      getActivity().sendBroadcast(intent);
  }
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Bundle bundle = getArguments();
        if (bundle != null)
            mArgument = bundle.getString(ARGUMENT);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        if (mContentView == null) {
            mContentView = inflater.inflate(R.layout.activity_ec_main, null);
            initView();
            home_viewPager.setOffscreenPageLimit(4);
            getTabData();
            bindAdapter();
            initListener();
        } else {
            ViewGroup parent = (ViewGroup) mContentView.getParent();
            if (parent != null) {
                parent.removeView(mContentView);
            }
        }
        return mContentView;
    }

    private void initListener() {
        imageView_search.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(getActivity(), Search_Activity.class);
                startActivity(intent);
            }
        });
    }

    private void bindAdapter() {
        home_tabAdapter = new HomeTabLayoutAdapter(getChildFragmentManager(), getActivity(), home_tabData, home_tabFragment);
        home_viewPager.setAdapter(home_tabAdapter);
        home_tabLayout.setupWithViewPager(home_viewPager);

    }


    private void getTabData() {
        home_tabData.add("热销");
        home_tabData.add("采摘");
        home_tabData.add("进口");
        home_tabData.add("国产");
        url_data.add(HttpConfig.SubUrl.HOT_SALE);
        url_data.add(HttpConfig.SubUrl.SPECIAL_PRICE);
        url_data.add(HttpConfig.SubUrl.IMPORTED);
        url_data.add(HttpConfig.SubUrl.DOMESTIC);
        home_tabFragment.add(homeHotFragment);
        Hotbundle.putString("url", "1");
        homeHotFragment.setArguments(Hotbundle);

        home_tabFragment.add(homeBargainFragment);
        BargainBundle.putString("url", "2");
        homeBargainFragment.setArguments(BargainBundle);

        home_tabFragment.add(homeImportationFragment);
        ImportationBundle.putString("url", "4");
        homeImportationFragment.setArguments(ImportationBundle);

        home_tabFragment.add(homeDomesticFragment);
        DomesticBundle.putString("url", "3");
        homeDomesticFragment.setArguments(DomesticBundle);
        for (int i = 0; i < 4; i++) {
//            home_tabFragment.add(tabFragment);
//            Bundle bundle = new Bundle();
//            bundle.putString("url", url_data.get(i));
            home_tabLayout.addTab(home_tabLayout.newTab().setText(home_tabData.get(i)));
//            tabFragment.setArguments(bundle);
        }
//        home_tabLayout.addTab(home_tabLayout.newTab(), true);
//        home_tabLayout.set
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        thread = new Thread(new Runnable() {
            @Override
            public void run() {
                // 写子线程中的操作,解析省市区数据
                initJsonData();
            }
        });
        thread.start();

        mLocationClient = new AMapLocationClient(getContext());
////设置定位回调监听
        mLocationClient.setLocationListener(mLocationListener);
        //初始化AMapLocationClientOption对象
        mLocationOption = new AMapLocationClientOption();
        //设置定位模式为AMapLocationMode.Hight_Accuracy，高精度模式。
        mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
        //获取一次定位结果：
        //该方法默认为false。
        mLocationOption.setOnceLocation(true);
        mLocationOption.setInterval(1000);
        //获取最近3s内精度最高的一次定位结果：
        //设置setOnceLocationLatest(boolean b)接口为true，启动定位时SDK会返回最近3s内精度最高的一次定位结果。如果设置其为true，setOnceLocation(boolean b)接口也会被设置为true，反之不会，默认为false。
//        mLocationOption.setOnceLocationLatest(true);
        //给定位客户端对象设置定位参数
        mLocationClient.setLocationOption(mLocationOption);
        mLocationClient.startLocation();

        textView_tobar_left = (TextView) view.findViewById(R.id.textView_tobar_left);

        ((View)textView_tobar_left.getParent()).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (isLoaded) {
                    ShowPickerView();
                } else {
                    Toast.makeText(getContext(), "数据暂未解析成功，请等待", Toast.LENGTH_SHORT).show();
                }
            }
        });
    }

    private void ShowPickerView() {// 弹出选择器

        OptionsPickerView pvOptions = new OptionsPickerView.Builder(getContext(), new OptionsPickerView.OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int options2, int options3, View v) {
                //返回的分别是三个级别的选中位置
                String tx = options1Items.get(options1).getPickerViewText() +
                        options2Items.get(options1).get(options2) +
                        options3Items.get(options1).get(options2).get(options3);
                String s = options2Items.get(options1).get(options2);
                textView_tobar_left.setText(s);
                //通过Field.CITY_Name拿到当前城市默认青岛
                SharedPreferencesHelper.setString(SharedPreferencesHelper.Field.CITY_Name, s);
                sendaddress();
            }
        })

                .setTitleText("城市选择")
                .setDividerColor(Color.BLACK)
                .setTextColorCenter(Color.BLACK) //设置选中项文字颜色
                .setContentTextSize(20)
                .setOutSideCancelable(false)// default is true
                .build();

        /*pvOptions.setPicker(options1Items);//一级选择器
        pvOptions.setPicker(options1Items, options2Items);//二级选择器*/
        pvOptions.setPicker(options1Items, options2Items, options3Items);//三级选择器
        pvOptions.show();
    }

    private void initJsonData() {//解析数据

        /**
         * 注意：assets 目录下的Json文件仅供参考，实际使用可自行替换文件
         * 关键逻辑在于循环体
         *
         * */
        String JsonData = new GetJsonDataUtil().getJson(getContext(), "province.json");//获取assets目录下的json文件数据

        ArrayList<JsonBean> jsonBean = parseData(JsonData);//用Gson 转成实体

        /**
         * 添加省份数据
         *
         * 注意：如果是添加的JavaBean实体，则实体类需要实现 IPickerViewData 接口，
         * PickerView会通过getPickerViewText方法获取字符串显示出来。
         */
        options1Items = jsonBean;

        for (int i = 0; i < jsonBean.size(); i++) {//遍历省份
            ArrayList<String> CityList = new ArrayList<>();//该省的城市列表（第二级）
            ArrayList<ArrayList<String>> Province_AreaList = new ArrayList<>();//该省的所有地区列表（第三极）

            for (int c = 0; c < jsonBean.get(i).getCityList().size(); c++) {//遍历该省份的所有城市
                String CityName = jsonBean.get(i).getCityList().get(c).getName();
                CityList.add(CityName);//添加城市

                ArrayList<String> City_AreaList = new ArrayList<>();//该城市的所有地区列表

                //如果无地区数据，建议添加空字符串，防止数据为null 导致三个选项长度不匹配造成崩溃
                if (jsonBean.get(i).getCityList().get(c).getArea() == null
                        || jsonBean.get(i).getCityList().get(c).getArea().size() == 0) {
                    City_AreaList.add("");
                } else {

                    for (int d = 0; d < jsonBean.get(i).getCityList().get(c).getArea().size(); d++) {//该城市对应地区所有数据
                        String AreaName = jsonBean.get(i).getCityList().get(c).getArea().get(d);

                        City_AreaList.add(AreaName);//添加该城市所有地区数据
                    }
                }
                Province_AreaList.add(City_AreaList);//添加该省所有地区数据
            }

            /**
             * 添加城市数据
             */
            options2Items.add(CityList);

            /**
             * 添加地区数据
             */
            options3Items.add(Province_AreaList);
        }

        mHandler.sendEmptyMessage(MSG_LOAD_SUCCESS);

    }


    public ArrayList<JsonBean> parseData(String result) {//Gson 解析
        ArrayList<JsonBean> detail = new ArrayList<>();
        try {
            JSONArray data = new JSONArray(result);
            Gson gson = new Gson();
            for (int i = 0; i < data.length(); i++) {
                JsonBean entity = gson.fromJson(data.optJSONObject(i).toString(), JsonBean.class);
                detail.add(entity);
            }
        } catch (Exception e) {
            e.printStackTrace();
            mHandler.sendEmptyMessage(MSG_LOAD_FAILED);
        }
        return detail;
    }

    private void initView() {
        imageView_search = (ImageView) mContentView.findViewById(R.id.imageview_message);
        imageView_search.setImageResource(R.mipmap.search);
        imageView_search.setVisibility(View.VISIBLE);

        TextView textView = (TextView) mContentView.findViewById(R.id.toolbar_topname);
        textView.setText("妈妈爱果");
        textView.setVisibility(View.VISIBLE);

        LinearLayout layout_topbar_left = (LinearLayout) mContentView.findViewById(R.id.layout_topbar_left);
        layout_topbar_left.setVisibility(View.VISIBLE);
        TextView textView_tobar_left = (TextView) mContentView.findViewById(R.id.textView_tobar_left);
        textView_tobar_left.setText("青岛");
        textView_tobar_left.setVisibility(View.VISIBLE);
        ImageView imageView_tobar_left = (ImageView) mContentView.findViewById(R.id.imageview_topbar_left_backImage);
        imageView_tobar_left.setImageResource(R.mipmap.dizhi);
        imageView_tobar_left.setVisibility(View.VISIBLE);


        home_viewPager = (ViewPager) mContentView.findViewById(R.id.home_viewPager);
//        home_viewPager =mContentView.findViewById(R.id.home)
        home_tabLayout = (TabLayout) mContentView.findViewById(R.id.home_tabLayout);
        home_tabLayout.setTabMode(TabLayout.MODE_FIXED);
        home_tabData = new ArrayList<>();
        home_tabFragment = new ArrayList<>();
        url_data = new ArrayList<>();
        //==============================
        homeDomesticFragment = new HomeDomesticFragment();
        homeBargainFragment = new HomePickFragment();
        homeImportationFragment = new HomeImportationFragment();
        homeHotFragment = new HomeHotFragment();

 //===========================================================
        Hotbundle = new Bundle();
        DomesticBundle = new Bundle();
        ImportationBundle = new Bundle();
        BargainBundle = new Bundle();
    }
//    private void requestData() {
//    	RequestService.getInstance().getEcMainIndex(getActivity(), EcMainEntity.class, new RequestListener() {
//
//            @Override
//            public void onSuccess(int requestCode, BaseEntity resultData) {
//                if(resultData.isOk()){
//                    EcMainEntity entity = (EcMainEntity) resultData;
//                    EcMain data = entity.getData();
//                    setHotSell(data.getHotsell());
//                    setHotSupply(data.getHotsupply());
////                    setAdViewPager(data.getImages());
////                    adViewPager.setOnClickListener(new OnClickListener() {
////                        @Override
////                        public void onClick(View v) {
////
////                        }
////                    });
//                }else{
//
//                }
//            }
//
//            @Override
//            public void onFailed(int requestCode, Exception error, String msg) {
//            }
//        });
//    	RequestService.getInstance().mainIndex(getActivity(), 1 + "", MainEntity.class, new RequestListener() {
//
//            @Override
//            public void onSuccess(int requestCode, BaseEntity resultData) {
//
//                if (resultData.isOk()) {
//                    MainEntity result = (MainEntity) resultData;
//                    AccountManager.saveBaoxian(result.getData().getBx());
//                    setAdViewPager(result.getData().getFocus());
//
//                } else {
//                    ToastUtil.toast(resultData.getMsg());
//                }
//            }
//
//            @Override
//            public void onFailed(int requestCode, Exception error, String msg) {
//            }
//        });
//    }
//
//    private void setAdViewPager(List<FocusImage> images) {
//    	List<AdModel> dataList = new ArrayList<AdModel>();
//    	for (FocusImage focusImage : images) {
//            if("3".equals(focusImage.getPageid()))continue;//如果为 3  是物流图片
//
//    		AdModel aa = new AdModel();
//    		aa.setImageUrl(focusImage.getBigimg());
//            aa.setLinkUrl(focusImage.getUrl());
//            aa.setTitle(focusImage.getTitle());
//    		dataList.add(aa);
//    	}
//    	adViewPager.freshData(dataList);
//    	scrollView.smoothScrollTo(0, 0);
//    }
//
//	protected void setHotSupply(List<EcHotSell> hotsupply) {
//        EcmainGridviewAdapter<EcHotSell> adapter = new EcmainGridviewAdapter<>(getActivity(), hotsupply, false);
//        mGongyingHotGv.setAdapter(adapter);
//    }
//
//    protected void setHotSell(List<EcHotSell> hotsell) {
//        EcmainGridviewAdapter<EcHotSell> adapter = new EcmainGridviewAdapter<>(getActivity(), hotsell, false);
//        mSeasonHotGv.setAdapter(adapter);
//    }
//
//    private void initView() {
//        mTopbarView = (TopbarView) mContentView.findViewById(R.id.topbar);
//        mTopbarView.setCenterModel(TopbarView.ID_TITLE_INDEX_EC);
//        if(getActivity() instanceof MainTabActivity){
//        	mTopbarView.setLeftImage(R.drawable.navbar_menu);
//        	mTopbarView.setLeftClickListener(new OnClickListener() {
//
//        		@Override
//        		public void onClick(View v) {
//                    //取消左侧的侧滑
////        			((MainTabActivity) getActivity()).toggle();
//        		}
//        	});
//        }else if(getActivity() instanceof MyFragmentActivity){
//        	mTopbarView.setLeftView(true, true);
//        	/*
//        	mTopbarView.setLeftClickListener(new OnClickListener() {
//
//        		@Override
//        		public void onClick(View v) {
//        			getActivity().finish();
//        		}
//        	});*/
//        }
//
//        if (IMFactory.getUnreadCount() > 0) {
//        	mTopbarView.setRightImage(R.drawable.icon_message_unread_ad);
//        } else {
//        	mTopbarView.setRightImage(R.drawable.icon_message_ad);
//        }
//        mTopbarView.setRightClickListener(new OnClickListener() {
//
//            @Override
//            public void onClick(View v) {
//                if (AccountManager.isLogin()) {
////                    Intent intent = new Intent(getActivity(), MessageCenterActivity.class);
////                    getActivity().startActivity(intent);
//    					IMFactory.openConversation(getActivity());
//                } else {
//                    Intent intent = new Intent(getActivity(), LoginActivity.class);
//                    getActivity().startActivity(intent);
//                }
//            }
//        });
//        adViewPager = (AdViewPager) mContentView.findViewById(R.id.ec_home_ad_viewpager);
//        mSearchLayout = mContentView.findViewById(R.id.layout_search);
////        mSearchImage = (ImageView) mContentView.findViewById(R.id.imageview_search);
//        mSearchEdit = (TextView) mContentView.findViewById(R.id.tv_search);
//
//        mShangjiLayout = mContentView.findViewById(R.id.layout_shangji);
//        mGongyingLayout = mContentView.findViewById(R.id.layout_gongying);
//        mCaigouLayout = mContentView.findViewById(R.id.layout_caigou);
//        mWuliuLayout = mContentView.findViewById(R.id.layout_wuliu);
//        mServiceContactLayout = mContentView.findViewById(R.id.layout_service_contact);
//        mShuaihuoLayout = mContentView.findViewById(R.id.layout_shuaihuo);
//
////        mActionGv = (MeasureGridView) mContentView.findViewById(R.id.gv_action_list);
//        mSeasonHotGv = (MeasureGridView) mContentView.findViewById(R.id.gv_season_hot);
//        mGongyingHotGv = (MeasureGridView) mContentView.findViewById(R.id.gv_gongying_hot);
//        scrollView = (ScrollView) mContentView.findViewById(R.id.sv_ec_main);
//    }
//
//    private void setUpView() {
//    	mShangjiLayout.setOnClickListener(this);
//    	mGongyingLayout.setOnClickListener(this);
//    	mCaigouLayout.setOnClickListener(this);
//    	mWuliuLayout.setOnClickListener(this);
//    	mServiceContactLayout.setOnClickListener(this);
//    	mShuaihuoLayout.setOnClickListener(this);
//    	mSearchLayout.setOnClickListener(this);
//
//
//		mSeasonHotGv.setOnItemClickListener(new OnItemClickListener() {
//
//			@Override
//			public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//			    EcHotSell item = (EcHotSell) parent.getItemAtPosition(position);
//				Intent intent = new Intent (getActivity(),SeasonHotActivity.class);
//				intent.putExtra(ExtraName.isSupply, false);
//				intent.putExtra(ExtraName.bigpid, item.getBigpid());
//				intent.putExtra(ExtraName.catid, item.getCatid());
//				intent.putExtra(ExtraName.title, item.getTitle());
//				getActivity().startActivity(intent);
//			}
//		});
//		mGongyingHotGv.setOnItemClickListener(new OnItemClickListener() {
//
//			@Override
//			public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//			    EcHotSell item = (EcHotSell) parent.getItemAtPosition(position);
//				Intent intent = new Intent (getActivity(),SeasonHotActivity.class);
//				intent.putExtra(ExtraName.isSupply, true);
//				intent.putExtra(ExtraName.bigpid, item.getBigpid());
//                intent.putExtra(ExtraName.catid, item.getCatid());
//                intent.putExtra(ExtraName.title, item.getTitle());
//				getActivity().startActivity(intent);
//			}
//		});
//    }
//
//    @Override
//    public void onClick(View v) {
//        switch (v.getId()) {
//        case R.id.layout_shangji:
//            //目前改为品牌直营
//            gotoBrandScopePage();
//            break;
//        case R.id.layout_gongying:
//        	getActivity().startActivity(new Intent(getActivity(),SupplyHallActivity.class));
//            MobclickAgent.onEvent(getActivity(), UMengEventID.CLICK_EC_MAIN_SUPPLY_HALL);
//        	break;
//        case R.id.layout_caigou:
//        	getActivity().startActivity(new Intent(getActivity(),PurchaseHallActivity.class));
//            MobclickAgent.onEvent(getActivity(), UMengEventID.CLICK_EC_MAIN_PURCHASE_HALL);
//        	break;
//        case R.id.layout_wuliu:
//        	getActivity().startActivity(new Intent(getActivity(),MyLogisticsActivity.class));
//        	break;
//        case R.id.layout_service_contact:
//        	IMFactory.openChatServiceContact(getActivity());
//        	break;
//        case R.id.layout_shuaihuo:
//        	getActivity().startActivity(new Intent(getActivity(),DumpHallActivity.class));
//        	break;
//        case R.id.layout_search:
//            getActivity().startActivity(new Intent(getActivity(),SearchActivity.class));
////            AndroidUtils.sendweixin(getActivity(), "京东方", "的发个梵蒂冈", "http://www.baidu.com");
//            break;
//        }
//
//    }
//
//    /**
//     * 进入品牌直营页面
//     */
//    private void gotoBrandScopePage() {
//        //交互逻辑：1、访问用户是否已经授权。是：直接进入直营商品页面； 否：分两种情况，从未申请时，进入提交申请表单页面，如果已经申请，提示正在进行审核。
//        //更新用户资料
//        AccountManager.updateUserInfo(getContext(), new UserInfoListener() {
//            @Override
//            public void onUpdateUserInfo(UserInfoEntity userInfoEntity) {
//                BrandScope brandScope = userInfoEntity.getData().getBrandScope();
//                if (brandScope == null || StringUtil.isEmpty(brandScope.getName())) {
//                    getActivity().startActivity(new Intent(getActivity(), BrandScopeApplyActivity.class));
//                } else if (brandScope.getAuditStatus() == BrandScopeStatus.IN_AUDITING) {
//                    //TODO 弹出审核中提示
//                    final MessageDialog dialog = new MessageDialog(getContext());
//                    dialog.setMessage("品牌直营准入资料正在审核中，请耐心等待。");
//                    dialog.setLeftBtVisible(false);
//                    dialog.setOnBtClickListener(new MessageDialog.OnBtClickListener() {
//                        @Override
//                        public void onLeftBtClick() {
//
//                        }
//
//                        @Override
//                        public void onRightBtClick() {
//                            dialog.dismiss();
//                        }
//                    });
//                    dialog.show();
//                } else if (brandScope.getAuditStatus() == BrandScopeStatus.FAILURE_AUDIT) {
//                    //TODO 弹出审核失败提示，可以选择重新审核
//                    final MessageDialog dialog = new MessageDialog(getContext());
//                    dialog.setMessage("抱歉，品牌直营用户资料，审核未通过！");
//                    dialog.setLeftBtText("重新审核");
//                    dialog.setRightBtText("取消");
//                    dialog.setOnBtClickListener(new MessageDialog.OnBtClickListener() {
//                        @Override
//                        public void onLeftBtClick() {
//                            getActivity().startActivity(new Intent(getActivity(), BrandScopeApplyActivity.class));
//                            dialog.dismiss();
//                        }
//
//                        @Override
//                        public void onRightBtClick() {
//                            dialog.dismiss();
//                        }
//                    });
//                    dialog.show();
//                } else if (brandScope.getAuditStatus() == BrandScopeStatus.SUCCEED_AUDIT) {
//                    getActivity().startActivity(new Intent(getActivity(), BrandScopeActivity.class));
//        //        	    getActivity().startActivity(new Intent(getActivity(),BusinessOpportunityActivity.class));
//                }
//            }
//        });
//    }
//
//    @Override
//    public void onResume() {
//        super.onResume();
//        MobclickAgent.onPageStart("EcMainFragment");
//    }
//
//    @Override
//    public void onPause() {
//        super.onPause();
//        MobclickAgent.onPageEnd("EcMainFragment");
//    }
}
